package com.sec.etech.org.aop;

import com.alibaba.fastjson.JSONObject;
import com.sec.etech.common.LifeCycle;
import com.sec.etech.org.service.EtechRelationService;
import com.sec.etech.sys.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component("orgGroupManagers")
public class OrgGroupManagers implements LifeCycle {
    @Autowired
    EtechRelationService etechRelationService;

    @Override
    public boolean checkPermission(HttpServletRequest request, HttpServletResponse response, JSONObject data) throws Exception {
        boolean isProd = PropertyUtil.getPropertyService().getByAlias("systemEnvironmentVariables").equals("prod");

        if (isProd) {
            throw new Exception("组织、菜单、角色、设计科室、部门主管助理内勤请在测试服中修改，并联系程序员同步到生产服");
        }
        return true;
    }

    @Override
    public void beforeSave(HttpServletRequest request, HttpServletResponse response, JSONObject data) {

    }

    @Override
    public void afterSave(HttpServletRequest request, HttpServletResponse response, JSONObject data) {
        etechRelationService.syncRole("manager");
    }

    @Override
    public String permissionDenied() {
        return null;
    }
}
